//
//  BuyFuelTest.cpp
//  SpaceTrader
//
//  Created by Brandon Chastain on 11/19/12.
//  Copyright (c) 2012 The Hex Pistols. All rights reserved.
//

#include "BuyFuelTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(BuyFuelTest);

void BuyFuelTest::setUp()
{
    player = new Player();
}

void BuyFuelTest::reset()
{
    player->getShip()->setFuel(0);
    player->setCredits(1000);
}

void BuyFuelTest::tearDown()
{
    free(player);
}

void BuyFuelTest::testIdealBuy()
{
	reset();

    int res = player->buyFuel(1, 10);
    CPPUNIT_ASSERT(res == 0);
    CPPUNIT_ASSERT(player->getFuel() == 1);
}

void BuyFuelTest::testMoreThanCapacityBuy()
{
	reset();

    int res = player->buyFuel(400, 1);
    CPPUNIT_ASSERT(res == 0);
    CPPUNIT_ASSERT(player->getFuel() == player->getShip()->getCapacity());
}

void BuyFuelTest::testAtFullCapacityBuy()
{
	reset();

    player->getShip()->setFuel(player->getShip()->getCapacity());
    int res = player->buyFuel(300, 1);
    CPPUNIT_ASSERT(res == 2);
    CPPUNIT_ASSERT(player->getFuel() == player->getShip()->getCapacity());
    CPPUNIT_ASSERT(player->getCredits() == 1000);
}

void BuyFuelTest::testNotEnoughCreditsBuy()
{
	reset();
	
    player->setCredits(0);
    int res = player->buyFuel(100, 100);
    CPPUNIT_ASSERT(res == 1);
    CPPUNIT_ASSERT(player->getFuel() == 0);
    CPPUNIT_ASSERT(player->getCredits() == 0);
}


